from book.models import Book
from utils.serializers import CustomModelSerializer
from utils.viewset import CustomModelViewSet


# ================================================= #
# ************** 书籍管理 view  ************** #
# ================================================= #

class BookSerializer(CustomModelSerializer):
    """
    书籍 -序列化器
    """

    class Meta:
        model = Book
        read_only_fields = ["id"]
        fields = '__all__'

class BookCreateUpdateSerializer(CustomModelSerializer):
    """
    书籍管理 创建/更新时的列化器
    """

    class Meta:
        model = Book
        fields = '__all__'


class BookViewSet(CustomModelViewSet):
    """
    书籍管理接口
    list: 查询
    create: 新增
    update: 修改
    retrieve: 单例
    destroy: 删除
    """
    queryset = Book.objects.all()
    serializer_class = BookSerializer
    extra_filter_backends = []
    permission_classes = []
    search_fields = ['label']